////////////////////////////////////////
// EECE478 COMPUTER GRAPHICS
// Spring term 2011
// Assignment 3 City Rendering
// (Tim) Wei-Ting Liu
// #29144052
////////////////////////////////////////

#include <string>
#include "loadCity.h"

using namespace std;

loadCity::loadCity(string cityFile){
	ifstream inFile(cityFile, ios::binary);
	if(inFile.is_open()){
		int counter = 0;
		while(inFile.good()){
			string line;
			getline(inFile, line);
			vector<string> subString;
			string buffer;
			stringstream sStream(line);

			while(sStream >> buffer){
				subString.push_back(buffer);
			}
			if(subString.size() != 0){

				if(subString[0][0] != '#'){
					if(counter == 0){ }											// Student Number
					if(counter == 1) cityName = subString[0];					// City Name
					if(counter == 2){ 
						numOfModel = atoi(subString[0].c_str());				// Number of Model files
						if(numOfModel < 10){
							cout << "Please provide at least 17 model files to render the city properly!\n";
							exit(1);
						}
					}
					if(counter > 2){											// Model Scaling Factors
						modelName.push_back(subString[0]);
						vector<float> modelScale;
						if(subString.size() != 13){
							cout << "Model scaling factors does not have 13 elements at line: " << counter << endl;
							exit(1);
						}else{
							for(int i=0; i<12; i++){
								modelScale.push_back(atof(subString[i+1].c_str()));
							}
							scalingFactor.push_back(modelScale);
						}
					}
					counter++;
				}
			}
		}
		inFile.close();
		if(counter != numOfModel+3){
			cout << "ERROR: Cityfile: Number of model file does not match the number specified." << endl;
			exit(1);
		}
	}else{
		cout << "Unable to open model file: " << cityFile << endl;
		exit(1);
	}
}

string loadCity::getCityName(){
	return cityName;
}

int loadCity::getNumOfModel(){
	return numOfModel;
}

vector<string> loadCity::getModelName(){
	return modelName;
}

vector<vector<float>> loadCity::getScalingFactor(){
	return scalingFactor;
}